package es.prodevelop.arport;

import java.io.IOException;
import java.net.URI;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;

import android.content.Intent;
import es.prodevelop.arport.util.Utils;

public class ARLeisureActivity extends ARBrowserActivity {

	@Override
	public boolean urlWasInvoked(String url) {
		// parsing the retrieved url string
		List<NameValuePair> queryParams = URLEncodedUtils.parse(
				URI.create(url), "UTF-8");

		String id = "";
		// getting the values of the contained GET-parameters
		for (NameValuePair pair : queryParams) {
			if (pair.getName().equals("id")) {
				id = pair.getValue();
			}
		}

		// get the corresponding poi bean for the given id
		// PoiBean bean = poiBeanList.get(Integer.parseInt(id));
		// start a new intent for displaying the content of the bean
		Intent intent = new Intent(this, PoiActivity.class);
		intent.putExtra("POI_ID", id);
		intent.putExtra("LEISURE", true);

		this.startActivity(intent);
		return true;
	}

	@Override
	protected void loadARWorld() throws IOException {
		getArchitectView().load("arport.html");

		getArchitectView().callJavascript(
				"newData(" + Utils.loadLeisurePoiBeans(this) + ");");
	}

}
